<?=$this->load->view('admin/job/job_create_header')?>
<div class="job_create_obj">










<!-- #############################################
	
			Type of the job:
	
	############################################# -->
<?php if($link == 'type'):?>
	<div style="float:right; "><?php $this->load->view('templates/img/type'); ?></div>
	<div class="job_create">
	<h2>Select job type:</h2>
	<form accept-charset="utf-8" method="post" action="<?=site_url('admin/job_generate')?>/<?=$this->uri->segment(3)?>/type_submit">
		<input type="radio" value="1" name="job_type" <?php if(isset($type_repopulate)){if($type_repopulate == 1){echo 'CHECKED';}}?>> Repair <br />
		<input type="radio" value="2" name="job_type" <?php if(isset($type_repopulate)){if($type_repopulate == 2){echo 'CHECKED';}}?>> Site visit <br />
		<input type="radio" value="3" name="job_type" <?php if(isset($type_repopulate)){if($type_repopulate == 3){echo 'CHECKED';}}?>> Remote help <br />
		<input type="radio" value="4" name="job_type" <?php if(isset($type_repopulate)){if($type_repopulate == 4){echo 'CHECKED';}}?>> Custom build <br />
		<input type="radio" value="5" name="job_type" <?php if(isset($type_repopulate)){if($type_repopulate == 5){echo 'CHECKED';}}?>> Refurbished computer <br />
		<br />

		<input type="submit" value="Submit" />
	<?=form_close()?>
	</div>
<?php endif;?>













<!-- #############################################
	
			Customer search box:
	
	############################################# -->
<?php if($link == 'customer_select'):?>
<div style="float:right; "><?php $this->load->view('templates/img/customer'); ?></div>
<div class="job_create">	
	<?php if (isset($customer_already_selected)){
		echo '<h2 style="color:red;">The customer has already been selected/created!</h2>';
	}
	?>
	<h2>Find a customer</h2>
	<form accept-charset="utf-8" method="post" action="<?=site_url('admin/job_generate')?>/<?=$this->uri->segment(3)?>/customer_select">
	<input type="text" name="customer" />
	<input type="checkbox" name="business"> Business<br />
	<input type="submit" value="Submit">
	<?=form_close()?>
	
<!-- #############################################
	
			Customer search result:
	
	############################################# -->	
	<div class="customer_search_results">
		<?php 				
		
		// search results for normal customers: 
		if (!empty($result) and !$is_business_customer){

			echo '
					<table>
						<thead>
							<tr>
								<th>Id</th>
								<th>Name</th>
								<th>Phone</th>
								<th>Address</th>
							</tr>
						</thead>';
			foreach ($result as $row){
				//link creator:
				$link = site_url('admin/job_generate').'/'.$this->uri->segment(3).'/customer_submit/'.$row['ID'];
				echo '<tr>';
					echo '<td id="table_short">';
						echo '<a href="'.$link.'" id="table_short">';
							echo $row['ID'];
						echo '</a>';
					echo '</td>';
					
					echo '<td>';
						echo '<a href="'.$link.'">';
							echo $row['name'];
						echo '</a>';
					echo '</td>';
										
					echo '<td>';
						echo '<a href="'.$link.'">';
							echo $row['phone'];
						echo '</a>';
					echo '</td>';
					
					echo '<td >';
						echo '<a href="'.$link.' " style="min-width:1px;">';
							echo $row['address'];
						echo '</a>';
					echo '</td>';
					

					 
					
				echo '</tr>';
				
			}
			
			echo '</table>';
		    
		}




// search results for business customers: 
		if (!empty($result) and $is_business_customer){
		  
			echo '
					<table>
						<thead>
							<tr>
								<th>Id</th>
								<th>Name</th>
								<th>Phone</th>
								<th>Company</th>
								
							</tr>
						</thead>';
			foreach ($result as $row){
				//link creator:
				$link = site_url('admin/job_generate').'/'.$this->uri->segment(3).'/customer_submit/'.$row['ID'];
				echo '<tr>';
					echo '<td id="table_short">';
						echo '<a href="'.$link.'" id="table_short">';
							echo $row['ID'];
						echo '</a>';
					echo '</td>';
					
					echo '<td>';
						echo '<a href="'.$link.'">';
							echo $row['name'];
						echo '</a>';
					echo '</td>';
					
					echo '<td>';
						echo '<a href="'.$link.'">';
							echo $row['phone'];
						echo '</a>';
					echo '</td>';
					
					/*echo '<td >';
						echo '<a href="'.$link.' " style="min-width:1px;">';
							echo $row['address'];
						echo '</a>';
					echo '</td>';
					
					echo '<td  id="table_short">';
						echo '<a href="'.$link.'"  id="table_short">';
							echo $row['type'];
						echo '</a>';
					echo '</td>';
					 * 
					 */
					echo '<td >';
						echo '<a href="'.$link.'">';
							echo $row['business_name'];
						echo '</a>';
					echo '</td>';
				echo '</tr>';
				
			}
			}
			echo '</table>';

		?>
</div>

	
	
<!-- #############################################
	
			Customer create new:
	
	############################################# -->

	<br />


	<div class="customer_create_wrap">
		<form accept-charset="utf-8" method="post" action="<?=site_url('admin/job_generate')?>/<?=$this->uri->segment(3)?>/customer_select_create">

		<div class="customer_create_customer">
			<h2>New customer name:</h2>
			<select name="title">
				<option value=''></option>
				<?php foreach ($titles as $row): ?>
					<option 
						value="<?=$row->idtitle?>"
						<?php if(set_value('title')==$row->idtitle){ echo 'SELECTED';};?>
					>
						<?=$row->title?>
					</option>
				<? endforeach ?>
			</select>
			
			<input type="text" name="name" id="create_customer_name" value="<?=set_value('name')?>" /><br />
			
			Phone<br /> <input type="text" name="phone" value="<?=set_value('phone')?>" /><br />
			
			@mail<br /><input type="text" name="email" value="<?=set_value('email')?>"/><br />
			
			Select Business: 
			<br />
			<select name="business_name" id="business_name_dropdown">
				<option value="0">None</option>
				<?php foreach ($business_list as $row): ?>
				<option 
					value="<?php echo $row->idbusiness_name;?>"


					<?php 
					if (isset($_POST['business_name'])){
						if($_POST['business_name'] == $row->idbusiness_name){
						 echo 'SELECTED';};
						
					};
					?>	

					>
					<?php echo $row->name;?>
									
				</option>


				
				<?php endforeach; ?>
				

			</select>
			</div>
			
			<div class="customer_create_address">
				<h2>Address:</h2>
				<input type="text" name="field1" value="<?=set_value('field1')?>" /> <br />
				<input type="text" name="field2" value="<?=set_value('field2')?>" ><br />
				PostCode<br />
				<input type="text" name="postcode" value="<?=set_value('postcode')?>" ><br />
			</div>
			
			<div id="validation_errors1"><?php echo validation_errors(); ?></div>
	</div>
		<input type="submit" value="Submit" id="customer_create_submit">
</div>	
	
<?php endif;?>





<!-- #############################################
	
			Job description:
	
	############################################# -->
<?php if($link == 'description'):?>
	<div style="float:right; "><?php $this->load->view('templates/img/description'); ?></div>
<div class="job_create">
		
	<h2>Describe the task:</h2>
	<form accept-charset="utf-8" method="post" action="<?=site_url('admin/job_generate')?>/<?=$this->uri->segment(3)?>/submit_job_descr">
		<textarea name="job_descr" style="width:30em; font-family:arial;font-size:18pt;" class="textor" ><?php 
		 		if(isset($description_repopulate)){
		 		echo $description_repopulate;
		 		}
			?></textarea>
		<br /><br />
		<input type="submit" value="Submit"> 
	 
	<?=form_close()?>

	
</div>	
<?php endif;?>









<!-- #############################################
	
			Target time:
	
	############################################# -->
<?php if($link == 'time'):?>
<div class="job_create">
	<h2>Select the date:</h2>
	<form accept-charset="utf-8" method="post" action="<?=site_url('admin/job_generate')?>/<?=$this->uri->segment(3)?>/items">

	</script><div class="demo"><p><input id="datepicker" type="text" name="time" 
		<?php
		if (isset($selected_date['time'])){
			echo 'value="'.$selected_date['time'].'"';
		}
		?>
		></p></div>
	<div style="display: none;" class="demo-description">
		</div>
	<input type="submit" value="Submit"> 
	<?=form_close()?>
</div>	
	
<?php endif;?>











<!-- #############################################
	
			Number of items:
	
	############################################# -->
<?php if($link == 'items'):?>
	<div style="float:right; "><?php $this->load->view('templates/img/peripherals'); ?></div>
<div class="job_create">
	
	<h2>Items booked in:</h2>
	<form accept-charset="utf-8" method="post" action="<?=site_url('admin/job_generate')?>/<?=$this->uri->segment(3)?>/items_submit">
		<?php
		if(isset($repopulated_items)){
			$item1 = $repopulated_items['item1'];
			$item2 = $repopulated_items['item2'];
			$item3 = $repopulated_items['item3'];
		}else{
			$item1 = $item2 = $item3 = '';
		}
	?>	
		
		
		
	<input type="text" name="item1" value="<?=$item1?>"><br />
	<input type="text" name="item2" value="<?=$item2?>"><br />
	<input type="text" name="item3" value="<?=$item3?>"><br />

	<input type="submit" value="submit"> 
	
	<?=form_close()?>

		</div>
	
	
<?php endif;?>











<!-- #############################################
	
			Payment information:
	
	############################################# -->
	
	
<?php if($link == 'payment'):?>
<div class="job_create">
	<form accept-charset="utf-8" method="post" action="<?=site_url('admin/job_generate')?>/<?=$this->uri->segment(3)?>/payment_submit">
	<div class="payment_totals">
	<table>
		
<!-- #############################################
	
			Totals charge:
	
	############################################# -->
							
		<tr>
					<td></td>
					<td style="text-align:right; padding-right:1em;">
						<div id="total"></div>
						
					</td>
					<td></td>
					<td></td>
				</tr>
				
				
				
				
<!-- #############################################
	
			minimum charge:
	
	############################################# -->
					
				
				<tr>
					<td></td>
					<td style="text-align:right;padding-right:1em;">Minimum Charge (diagnostic): </td>
					<td>£</td>
					<td>
						<select name="min_charge" id="min_charge">
							<?php if(!isset($min_charge)){
								$min_charge = 0;
							}
							?>
							<option value="3" <?php if($min_charge == 3){echo 'SELECTED';}?>
												<?php if($min_charge == 0){echo 'SELECTED';}?>>50  (diagnostic)</option>
							<option value="2" <?php if($min_charge == 2){echo 'SELECTED';}?>>30  (half an hour labour)</option>
							<option value="1" <?php if($min_charge == 1){echo 'SELECTED';}?>>0  (warranty repair)</option>
						</select> 
					</td>
					<td></td>
					<td></td>
					<td><input type="submit" value="submit" id="payment_submit"></td>
				</tr>
				<tr>
					<td></td>
<!-- #############################################
	
			Hour rate
	
	############################################# -->
						
					<td style="text-align:right;padding-right:1em;">
						Planned Labour Hours @ rate 
							
					</td>
					<td>£</td>
					<td>
						<select name="planned_hours" id="rate" >
							<option value="1" <?php if(isset($planned_hours)){if($planned_hours == 1){echo 'SELECTED';}}?>>50  (Standard charge)</option>
							<option value="2" <?php if(isset($planned_hours)){if($planned_hours == 2){echo 'SELECTED';}}?>>65  (FastTrack)</option>
							<option value="3" <?php if(isset($planned_hours)){if($planned_hours == 3){echo 'SELECTED';}}?>>60  (Business)</option>
							<option value="4" <?php if(isset($planned_hours)){if($planned_hours == 4){echo 'SELECTED';}}?>>80  (BusinessFasttrack)</option>
							<option value="0" <?php if(isset($planned_hours)){if($planned_hours == 0){echo 'SELECTED';}}?>>0</option>
							<option value="5" <?php if(isset($planned_hours)){if($planned_hours == 5){echo 'SELECTED';}}?>>50  (remote connection)</option>
						</select> 
						
					</td>
					<td>
						
						x
					</td>
<!-- #############################################
	
			Hour count:
	
	############################################# -->
						
					<td><select name="hours_count">
							<option value="0" <?php if(isset($hours_count)){if($hours_count == 0){echo 'SELECTED';}}?>>0</option>
							<option value="0.5" <?php if(isset($hours_count)){if($hours_count == 0.5){echo 'SELECTED';}}?>>0.5</option>
							<option value="1" <?php if(isset($hours_count)){if($hours_count == 1){echo 'SELECTED';}}
													if (!isset($hours_count)){echo 'SELECTED';}?>>1</option>
							<?php for($i=2; $i<=20; $i++): ?>
								<option value="<?=$i?>" <?php if(isset($hours_count)){if($hours_count == $i){ echo 'SELECTED';}}?>><?=$i?></option>';
							<?php endfor; ?>
						</select> 
					</td>
					
				</tr>
<!-- #############################################
	
			additional fee:
	
	############################################# -->
					
				<tr>
					<td></td>
					<td>Additional options:</td>
					<td>£</td>
					<td>
						<select id="optional_fee" name="optional_fee">
						<option value="0" <?php if(isset($optional_fee)){if($optional_fee == 1){echo 'SELECTED';}}?>>0 none</option>
						<option value="1" <?php if(isset($optional_fee)){if($optional_fee == 1){echo 'SELECTED';}}?>>50 call out</option>
						<option value="2" <?php if(isset($optional_fee)){if($optional_fee == 2){echo 'SELECTED';}}?>>30 local call out</option>
						
						</select>
					</td>
					<td></td>
					<td></td>
				</tr>
	</table>
	</div>
<!-- #############################################
	
			Other Items:
	
	############################################# -->
		
	
		<?php
		if (isset($repopulated_charge_items)){
			$i = 3;
			for ($i=1; $i<=10; $i++){
				$repopulated_items[$i]=$repopulated_charge_items[$i];
				$repopulated_items[$i.'v']=$repopulated_charge_items[$i.'v'];
				$repopulated_items[$i.'q']=$repopulated_charge_items[$i.'q'];
				}
		}else{
			for ($i=1; $i<=10; $i++){
				$repopulated_items[$i]='';
				$repopulated_items[$i.'v']='';
				$repopulated_items[$i.'q']='';
			}
		}
		?>
		<table>
			<tr>
				<th></th>
				<th>Item</th>
				<th></th>
				<th>UP</th>
				<th></th>
				<th>Quantity</th>
				
			</tr>
			<?php for ($i=1; $i<=10; $i++): ?>
				<tr>
					<td><?=$i?>:</td>
					<td><input type="text" name="payment<?=$i?>" value="<?=$repopulated_items[$i]?>"></td>
					<td>£</td>
					<td><input type="text" name="paymentv<?=$i?>" value="<?=$repopulated_items[$i.'v']?>" class="money" id="money"></td>
					<td>x:</td>
					<td><input type="text" name="paymentq<?=$i?>" value="<?=$repopulated_items[$i.'q']?>" id="money"></td>					

				</tr>
			<?php endfor; ?>
				
		</table>

	<?=form_close()?>


	</div>

	
<?php endif;?>





<!-- #############################################
	
			Submit Validation / Confirmation
	
	############################################# -->


<?php if($link == 'validate'):?>
	<div style="float:right; "><?php $this->load->view('templates/img/description'); ?></div>
<div class="job_create">
		
	<h2>Data verification</h2>
	<div class="data_verification">
	<?php if (isset($error)){
		echo 'Not quite there yet!<br /> Here is the error message:<h3>';
		echo $error;
		echo '</h3>';
	}elseif($confirm_button){
		?>
		<!-- if all checks are passed it's time to confirm the entry --->
		<form accept-charset="utf-8" method="post" action="<?=site_url('admin/job_generate')?>/<?=$this->uri->segment(3)?>/generate">
		<form 
		<span>Please confirm:</span><br />
		<input type="submit" value="confirm"/>
		</form>
		<?php
	}
	?>
	</div>
	
</div>	
<?php endif;?>










<div style="float:left; clear:both;">
<pre>
<?php
	print_r($this->session->userdata($this->uri->segment(3)));
 	//echo '<br />'.$link;

 
?>
</pre>


</div>







<!-- #############################################
	
			End main div
	
############################################# -->
</div>

<?php 
$this->load->view('templates/footer');
?>